package org.lalib.controller.action;

import java.util.List;

import org.lalib.acquire.IControllerAction;
import org.lalib.controller.form.CSearchForm;
import org.lalib.controller.service.CSearchService;
import org.lalib.entity.object.EItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Scope("request")
@Controller("cSearchAction")
public class CSearchAction implements IControllerAction {

	private static final long serialVersionUID = 1L;

	@Autowired
	CSearchForm cSearchForm;

	@Autowired
	CSearchService cSearchService;

	public String init() {
		return "searchPage";
	}

	public void searchForPerson() {
		String name = cSearchForm.getPersonName();
		Long id = cSearchForm.getPersonId();
		List<EItem> itemList = cSearchService.getUsersForGivenCriteria(name, id);
		cSearchForm.setItemList(itemList);
	}

	public void searchForFood() {
		String name = cSearchForm.getFoodName();
		Long id = cSearchForm.getFoodId();
		List<EItem> itemList = cSearchService.getFoodsForGivenCriteria(name, id);
		cSearchForm.setItemList(itemList);
	}

	public void searchForTable() {
		String name = cSearchForm.getTableName();
		Long id = cSearchForm.getTableId();
		List<EItem> itemList = cSearchService.getTablesForGivenCriteria(name, id);
		cSearchForm.setItemList(itemList);
	}
}